package cate.game.play.skill.passive.fairy;

import cate.game.play.buff.Buff;
import cate.game.play.config.PlayCfgArgs;
import cate.game.play.fighter.Fighter;
import cate.game.play.proce.action.ctx.ActionCtx;
import cate.game.play.proce.action.ctx.SkillActionCtx;
import cate.game.play.proce.action.ctx.TimeActionCtx;
import cate.game.play.proce.move.MoveCtx;
import cate.game.play.skill.passive.PassiveHandler;

/**
 * 效果1：“虚无附压”可无视控制直接释放。
 * 效果2：“虚无附压”眩晕目标大于等于2时为自身附加【余震】2回合，持续期间防御提升30%，
 * 效果3：“虚无附压”技能系数提升8%，并引爆所有被命中目标的【诅咒】，且有20%概率额外增加1层诅咒，【眩晕】概率提升5%。
 */
public class 深海八爪鱼灵器PH extends PassiveHandler {

	private String 技能标签;

	private String 眩晕标签;
	private int 眩晕目标;
	private int 自身buff;

	private String 引爆标签;

	//技能标签=虚无附压&
	//眩晕标签=眩晕&眩晕目标=2&自身buff=？？&
	//引爆标签=诅咒
	@Override
	public void parse(String code) {
		PlayCfgArgs args = new PlayCfgArgs(code);
		技能标签 = args.get("技能标签");

		眩晕标签 = args.get("眩晕标签");
		眩晕目标 = args.getInt("眩晕目标", 0);
		自身buff = args.getInt("自身buff", 0);

		引爆标签 = args.get("引爆标签");
	}

	@Override
	public void beforeOwnerMove(MoveCtx move, TimeActionCtx action) {
		if (move.getSkill().cfg.containTag(技能标签)) {
			move.getSkill().param.setIgnCtrlMove(true);
		}
	}

	private int buffAddNum;

	@Override
	public void onOtherAddBuff(ActionCtx action, Buff otherBuff) {
		if (otherBuff.caster.getPid() != skill.owner.getPid()) {
			return;
		}
		if (!otherBuff.cfg.containTag(眩晕标签)) {
			return;
		}
		if (!(action instanceof SkillActionCtx)) {
			return;
		}
		SkillActionCtx actionCtx = (SkillActionCtx) action;
		if (!actionCtx.getSkill().cfg.containTag(技能标签)) {
			return;
		}
		buffAddNum++;
	}

	@Override
	public void onOwnerMoveDone(MoveCtx move, TimeActionCtx action) {
		if (buffAddNum >= 眩晕目标) {
			skill.owner.buff.tryAddByTid(action, 自身buff);
		}
		buffAddNum = 0;
	}

	@Override
	public void afterOneAttack(SkillActionCtx action, long totalDamage, boolean strike, Fighter target) {
		if (!action.getSkill().cfg.containTag(技能标签)) {
			return;
		}
		target.buff.removeBuff(action, b -> b.cfg.containTag(引爆标签));
	}
}
